﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using Agnes.Core;
using Agnes.Libaray;

namespace Agnes.Startup
{
    [Serializable]
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Console.WriteLine("------------------------Agnes Personal Application Platform--------------------");
            Console.WriteLine("-----------------------------------------------------------Alpha 1-------------");

            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");

            Console.WriteLine("检查注册表文件关联.......");
            if (!AgnesFileTypeRegister.UpdateFileTypeRegInfo())
            {
                Console.WriteLine("进行解决方案关联......");
                AgnesFileTypeRegister.RegisterFileType();
            }

            if (args.Count() != 0)
            {
                Console.WriteLine(args[0]);
            }
            AgnesServiceManager.Instance.InitFinishedHandler += () =>
            {
                try
                {
                    if (args.Count() != 0)
                    {
                        AgnesServiceManager.AgnesSlnService.OpenSln(args[0]);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("该方案被加密过，不支持直接打开！");
                }

            };

            try
            {
                AgnesServiceManager.Instance.StartLaunchCodon();
                AgnesServiceManager.AgnesSlnService.OnSlnClosed(null, null);
                AgnesServiceManager.Instance.OnShutDown();
                AgnesServiceManager.AgnesSlnService.CloseAndSaveCurrentSln();
            }
            catch (Exception ex)
            {
                AgnesServiceManager.LogServ.Warn(ex.Message);
            }
        }
    }
}
